﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ADO.NET.Samples.Common;

namespace ADO.NET.Samples.Forms.EntityFramework
{
    [FormDescription("LINQ to Entities", "LINQ to Entities basic example.")]
    public partial class LINQtoEntitiesExample : Form
    {
        public LINQtoEntitiesExample()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Binding data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LINQtoEntitiesSample_Load(object sender, EventArgs e)
        {
            DBEntities db = new DBEntities();
            var articles = from article in db.Articles
                           where article.ArticleID < 5
                           orderby article.ArticleID descending, article.UserID ascending
                           select new { article.ArticleID, article.ArticleTitle, article.ArticleCategory.CategoryName, article.User.UserName };
            this.dataGridView1.DataSource = articles.AsEnumerable();
        }
    }
}
